<template>
  <div class="goods-container">
    <div class="goods-item" v-for="item in goodsList" :key="item._id">
      <router-link :to="'/home/goods-info/' + item._id">
        <img :src="item.src" :alt="item.alt">
        <p class="goods-name">{{item.name}}</p>

        <div class="info">
          <p class="price">
            <span class="price-now">￥{{item.old}}</span>
            <del class="price-old">￥{{item.now}}</del>
          </p>
          <p class="sell-info">
            <span>热卖中</span>
            <span>剩余{{item.remain}}件</span>
          </p>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      goodsList: []
    }
  },
  created () {
    this.getGoodsList();
  },
  methods: {
    getGoodsList: function () {
      this.$axios.get('http://sakumyz.xyz/api/goods-list')
        .then(res => {
          this.goodsList = res.data;
        })
        .catch(err => {
          console.log(err)
        });
    }
  },
}
</script>

<style lang="scss" scoped>
p {
  margin: 0;
  padding: 3px;
}
.goods-container {
  display: flex;
  flex-wrap: wrap; // 换行
  justify-content: space-between;
  padding: 7px;

  .goods-item {
    width: 49%;
    border: 1px solid #eee;
    box-shadow: 0 0 8px #ccc;
    margin: 4px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 245px;

    img {
      width: 100%;
    }

    .goods-name {
      color: #000;
    }

    .info {
      background-color: #efeff4;

      .price {
        .price-now {
          color: #e42727;
          margin-right: 8px;
          font-size: 16px;
          font-weight: bold;
        }

        .price-old {
          font-size: 14px;
        }
      }

      .sell-info {
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>
